<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>企业信用信息</title>
	<script src="../../js/header.js"></script>
</head>

<body>
<div v-cloak id="app">
	<div style="margin-top: 10px;">
		<el-form :model="selectForm" ref="selectForm" label-width="150px">
			<el-row>
				<el-col :span="4" class="tab-title">
					企业信用信息批量反馈
				</el-col>
			</el-row>
			<el-row style="margin-bottom: 10px;">
	            <el-col :span="20">
	            	<el-form-item label="信用评估结果明细导入附件:" prop="" label-width="220px">
	            		<el-input v-model="fileName1" style="width: 40%;"></el-input>
	            		<el-button type="primary" size="mini" @click="selectFile1()">选择文件</el-button>
		                <input type="file" id="excel1" ref="head1" accept=".xls,.xlsx" @change="checkType1()" enctype="multipart/form-data"/>		              
		                <el-button type="primary" size="mini" @click="uploadExcel()">批量反馈</el-button>
            		</el-form-item>	            		                
	            </el-col>
	        </el-row>
			<el-row style="margin-bottom: 10px;">
	            <el-col :span="20">
	            	<el-form-item label="信用线索企业详情导入附件:" prop="" label-width="220px">
		            	<el-input v-model="fileName2" style="width: 40%;"></el-input>
		                <el-button type="primary" size="mini" @click="selectFile2()">选择文件</el-button>
		                <input type="file" id="excel2" ref="head2" accept=".xls,.xlsx" @change="checkType2()" enctype="multipart/form-data"/>		              
		                <el-button type="primary" size="mini" @click="uploadExcel()">批量反馈</el-button>
		            </el-form-item>	    
	            </el-col>
	       </el-row>
	    </el-form>
	</div>	
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data() {
            return {
                uuid:'',
                link:'',//iframe链接
                link2:'',//iframe链接
                currentPage: 1, //默认显示页面为1
                pagesize: 10, // 每页的数据条数
                tableTotal:'',
                tableData: '',
				fileName1:'' , 
				fileName2:'' 
            }
        },
        created(){
        },
        mounted(){

        },
        methods: {
        	//选取文件
			selectFile1(){
				this.$refs.head1.click();
			},
			//选取文件
			selectFile2(){
				this.$refs.head2.click();
			},
			//检查上传类型
            checkType1() {
		          let vm = this;
		          let allImgExt = '.xls|.xlsx|';
		          let filePath = this.$refs.head1.value;
		          let extName = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
		          if (allImgExt.indexOf(extName + '|') === -1) {
		            this.$message("请选择正确的Excel文件");
		            this.$refs.head1.value = '';
		            excelContent = [];
		            return;
		          }
		          let file = this.$refs.head1.files[0];
		         this.fileName1 = file.name;
		   
        	},
        	//检查上传类型
            checkType2() {
		          let vm = this;
		          let allImgExt = '.xls|.xlsx|';
		          let filePath = this.$refs.head2.value;
		          let extName = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
		          if (allImgExt.indexOf(extName + '|') === -1) {
		            this.$message("请选择正确的Excel文件");
		            this.$refs.head2.value = '';
		            excelContent = [];
		            return;
		          }
		          let file = this.$refs.head2.files[0];
		         this.fileName2 = file.name;
		   
        	},
        	//导入
        	uploadExcel() {
                let that = this;
                let formData = new FormData();
                let file = this.$refs.head.files[0];
                if (file == "" || file == undefined) {
                    this.$message("请选择要导入的Excel文件");
                    return;
                }
                axios({
                    url: "http://10.13.16.78:8080/xzfy/xzfyLaws/addLawsFromExcel",
                    // url: "/dzjzfjg/detail/importToRemote",
					method: "post",
                    enctype: 'multipart/form-data',
                    data: formData,
                    processData: false, //重要
                    contentType: false, //重要
                    // dataType: 'json'
                }).then((res) => {
                    if (res.data.msg == "操作成功") {
                        this.$message({
                            message: '上传成功',
                            type: 'success'
                        });
                    } else if(res.data.msg == "操作失败") {
                        this.$message.error('上传失败');
                    } else {
                    	this.$message({
				          showClose: true,
				          duration: 0,
				          message: '重复文号:'+res.data.msg,
				          type: 'warning'
				        });
                    }
                }).catch(() => {
					if (formData.get('file').size == 0){
						this.$message.error("文件大小为0，请检查此路径下文件是否存在！");
					}else {
						this.$message.error('网络超时，请重新加载！')
					}
                });
            }

        }
    })
</script>
</body>
</html>